// 法一：拼接
const fn = (s) => {
  let leftStr = s.split(".")[0].split("").reverse().join("");
  let rightStr = s.split(".")[1];
  let len = leftStr.length;
  let newLeftStr = "";
  for (let i = 0; i < len; i++) {
    if ((i + 1) % 3 === 0 && i !== len - 1) {
      newLeftStr = newLeftStr + leftStr[i] + ",";
    } else {
      newLeftStr += leftStr[i];
    }
  }
  return newLeftStr.split("").reverse().join("") + "." + rightStr;
};

// 法二：正则
const fn2 = (s) => {
  let leftStr = s.split(".")[0];
  let rightStr = s.split(".")[1];
  let reg = /(?!^)(?=(\d{3})+$)/g;
  return leftStr.replace(reg, ",") + "." + rightStr;
};

// 法三：原生api
const fn3 = (s) => {
  // s需要是数字
  return s.toLocaleString();
};

console.log(fn3(34514325341));
